import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '../pages/Login/Login.vue'
import Shop from '../pages/Shop/Shop.vue'
import ShopGoods from '../pages/Shop/ShopGoods/Goods.vue'
import ShopRatings from '../pages/Shop/ShopRatings/Ratings.vue'
import ShopInfo from '../pages/Shop/ShopInfo/Info.vue'
import UserInfo from '../pages/UserInfo/UserInfo.vue'
import ShopType from '../pages/ShopType/ShopType.vue'

// import Home from '../pages/Home/Home.vue'
// import Order from '../pages/Order/Order.vue'
// import Personal from '../pages/Personal/Personal.vue'
// import Search from '../pages/Search/Search.vue'

const Home = () => import('../pages/Home/Home.vue')
const Order = () => import('../pages/Order/Order.vue')
const Personal = () => import('../pages/Personal/Personal.vue')
const Search = () => import('../pages/Search/Search.vue')

// 声明使用插件
Vue.use(VueRouter)

export default new VueRouter({
  // 配置路由
  routes: [
    {
      path: '/home',
      component: Home, // 返回路由组件函数，执行此函数才会加载路由组件。 路由懒加载，第一次访问才会加载路由
      // 源数据，组件中可通过$route.meta...获取。  通过获取该值是否显示footer组件
      // 不显示footer组件： 不写mate即可。 mete默认空数据，获取空数据等同于false
      meta: {
        showFooter: true
      }
    },
    {
      path: '/order',
      component: Order,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/personal',
      component: Personal,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/search',
      component: Search,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/userInfo',
      component: UserInfo
    },
    {
      path: '/shopType',
      component: ShopType
    },
    {
      path: '/shop',
      component: Shop,
      children: [
        {
          path: '/shop/goods', // 相对路径
          component: ShopGoods
        },
        {
          path: 'ratings', // 省略写法
          component: ShopRatings
        },
        {
          path: '/shop/info',
          component: ShopInfo
        },
        { // 默认路由
          path: '',
          redirect: '/shop/goods'
        }
      ]
    },
    { // 默认路由
      path: '/',
      redirect: '/home'
    }
  ]
})
